package NC98_判断t1树中是否有与t2树完全相同的子树;

import java.util.*;

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
}

public class Solution {
    /**
     *
     * @param root1 TreeNode类
     * @param root2 TreeNode类
     * @return bool布尔型
     */
    public boolean isContains (TreeNode root1, TreeNode root2) {
        // write code here
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        preorder(root1, sb1);
        preorder(root2, sb2);

        if (sb1.toString().contains(sb2.toString())){
            return true;
        }else {
            return false;
        }
    }

    private void preorder(TreeNode root, StringBuilder sb) {
        if (root == null){
            return;
        }
        preorder(root.left, sb);
        sb.append(root.val);
        preorder(root.right, sb);
    }
}